<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>学生成绩查看</title>
    <link rel="stylesheet" href="../static/layui/css/layui.css">
</head>
<body class="layui-layout-body">
    <div class="layui-layout layui-layout-admin">
        <div class="layui-header">
            <div class="layui-logo" style="height: 60px; line-height: normal; padding-top: 8px;">
                <div style="font-size: 16px; margin-bottom: 2px;">学生成绩查看</div>
                <div style="font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; color: rgba(255,255,255,.7);">
                    <span id="studentCode"></span>
                    <span id="studentName"></span>
                </div>
            </div>
            <ul class="layui-nav layui-layout-right">
<!--                <li class="layui-nav-item">-->
<!--                    <a href="javascript:;">-->
<!--                        <span th:text="${session.user.account}"></span>-->
<!--                    </a>-->
<!--                </li>-->
                <li class="layui-nav-item"><a href="http://localhost:63342/StudentManageSystem-Thymeleaf/templates/login.html">退出</a></li>
            </ul>
        </div>
        
        <div class="layui-body" style="padding: 15px;">
            <table id="gradeTable" lay-filter="gradeTable"></table>
        </div>
    </div>

    <script src="../static/layui/layui.js"></script>
    <script>
        layui.use(['table', 'element'], function(){
            var table = layui.table;
            var element = layui.element;
            var $ = layui.$;
            
            // 设置全局 Ajax 默认值
            $.ajaxSetup({
                xhrFields: {
                    withCredentials: true
                },
                crossDomain: true
            });
            
            // 获取当前登录学生信息
            $.ajax({
                url: 'http://localhost:8050/api/backend/user/current',
                type: 'GET',
                success: function(res) {
                    if (res.code === 200) {
                        $('#studentCode').text('学号: ' + res.data.code);
                        $('#studentName').text('姓名: ' + res.data.userName);
                    }
                }
            });
            
            // 初始化表格
            table.render({
                elem: '#gradeTable',
                url: 'http://localhost:8050/api/backend/grade/student/list',
                headers: {
                    'Content-Type': 'application/json'
                },
                xhrFields: {
                    withCredentials: true
                },
                parseData: function(res) {
                    return {
                        "code": res.code === 200 ? 0 : res.code, // layui 需要 code 为 0 表示成功
                        "msg": res.message,
                        "count": res.data.length,
                        "data": res.data
                    };
                },
                cols: [[
                    {field: 'courseName', title: '课程名称'},
                    {field: 'score', title: '成绩'},
                    {field: 'createTime', title: '创建时间', templet: function(d){
                        return d.createTime.split('T')[0] + ' ' + d.createTime.split('T')[1];
                    }}
                ]]
            });
        });
    </script>
</body>
</html> 